﻿function myLoginForm() {
	var win = null;
	var logoPanel = new Ext.Panel({
		baseCls : 'x-plain',
		margins : '0 100 0 100',
		region : 'center'
	});

	var formPanel = new Ext.FormPanel({
		id : 'loginForm',
		baseCls : 'x-plain',
		height : 100,
		labelAlign : 'right',
		defaultType : 'textfield',
		frame : false,
		items : [ {
			fieldLabel : TXT_login_username,
			id : 'j_username',
			name : 'j_username',
			width : 200
		}, {
			inputType : 'password',
			fieldLabel : TXT_login_password,
			id : 'j_password',
			name : 'j_password',
			width : 200
		} ],
		labelWidth : 150,
		region : 'south'
	});

	if (!win) {
		win = new Ext.Window({
			id : 'loginWin',
			defaultButton : 'btnLogin',
			buttons : [ {
				id : 'btnLogin',
				text : TXT_login_btn_login,
				handler : function() {
					win.getComponent('loginForm').form.submit({
						url : SECURITY_URL,
						waitTitle : TXT_common_hint,
						method : 'POST',
						waitMsg : TXT_login_waiting,
						success : function(form, action) {
							window.location.href = '../htm/index.htm';
						},
						failure : function(form, action) {
							if (action.result.message != null)
								Ext.MessageBox.alert(TXT_common_hint,
										action.result.message);
							else
								window.location.href = './login.htm';
						}
					});
				}
			} ],
			title : TXT_login_title,
			layout : 'border',
			width : 500,
			height : 250,
			closeAction : 'hide',
			closable : false,
			plain : false,
			draggable : false,
			resizable : false,
			items : [ logoPanel, formPanel ]
		});
	}
	win.on('show', function() {
		var f = Ext.get('j_username');
		f.focus.defer(100, f);
	});
	win.show(this);
}

Ext.onReady(myLoginForm);